﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Libs.HR;

public partial class Pages_Fix_FullName : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        List<Employees> list;
        list = new Employees().List();
        for (int i = 0; i < list.Count; i++)
        {
            var _Employee = new Employees();
            _Employee = list[i];
            _Employee.FirstName = FirstName(_Employee.FirstName);
            _Employee.LastName = LastName(_Employee.LastName);
            _Employee.Update();
        }
    }

    private string FirstName(string s)
    {
        // Lê Việt Hà
        s = s.Trim();
        while (s.IndexOf("  ") > 0)
        {
            s = s.Replace("  ", "");
        }
        for (int i = s.Length - 1; i > 0; i--)
        {
            if (s[i] == ' ') return s.Substring(i + 1, s.Length - i - 1);
        }
        return s;
    }

    private string LastName(string s)
    {
        // Lê Việt Hà
        s = s.Trim();
        while (s.IndexOf("  ") > 0)
        {
            s = s.Replace("  ", "");
        }
        for (int i = s.Length - 1; i > 0; i--)
        {
            if (s[i] == ' ') return s.Substring(0, i);
        }
        return s;
    }
}
